# vim:syntax=dockerfile
#------------------------------------------------------------------------------
# Dockerfile for building and testing Solidity Compiler on CI
# Target: Ubuntu 19.04 (Disco Dingo)
# URL: https://hub.docker.com/r/ethereum/solidity-buildpack-deps
#
# This file is part of solidity.
#
# solidity is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# solidity is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with solidity.  If not, see <http://www.gnu.org/licenses/>
#
# (c) 2016-2024 solidity contributors.
#------------------------------------------------------------------------------
FROM buildpack-deps:noble AS base
LABEL version="6"

ARG DEBIAN_FRONTEND=noninteractive

# From Python3.11, pip requires a virtual environment, and will thus terminate when installing packages globally.
# Since we're building this image from scratch, it's perfectly fine to use the below flag.
ENV PIP_BREAK_SYSTEM_PACKAGES=1

RUN set -ex; \
	z3_version="4.13.3"; \
	dist=$(grep DISTRIB_CODENAME /etc/lsb-release | cut -d= -f2); \
	echo "deb http://ppa.launchpad.net/ethereum/cpp-build-deps/ubuntu $dist main" >> /etc/apt/sources.list ; \
	apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1c52189c923f6ca9 ; \
	apt-get update; \
	apt-get install -qqy --no-install-recommends \
		build-essential \
		cmake \
		jq \
		libboost-filesystem-dev \
		libboost-program-options-dev \
		libboost-system-dev \
		libboost-test-dev \
		libcln-dev \
		locales-all \
		lsof \
		ninja-build \
		python3-pip \
		python3-sphinx \
		software-properties-common \
		sudo \
		unzip \
		zip; \
	pip3 install \
		codecov \
		colorama \
		deepdiff \
		parsec \
		pygments-lexer-solidity \
		pylint \
		requests \
		tabulate \
		z3-solver=="${z3_version}";

# Eldarica
RUN set -ex; \
	apt-get update; \
	apt-get install -qqy \
		openjdk-11-jre; \
	eldarica_version="2.1"; \
	wget "https://github.com/uuverifiers/eldarica/releases/download/v${eldarica_version}/eldarica-bin-${eldarica_version}.zip" -O /opt/eld_binaries.zip; \
	test "$(sha256sum /opt/eld_binaries.zip)" = "0ac43f45c0925383c9d2077f62bbb515fd792375f3b2b101b30c9e81dcd7785c  /opt/eld_binaries.zip"; \
	unzip /opt/eld_binaries.zip -d /opt; \
	rm -f /opt/eld_binaries.zip;

# CVC5
RUN set -ex; \
	cvc5_version="1.2.0"; \
	cvc5_archive_name="cvc5-Linux-x86_64-static"; \
	wget "https://github.com/cvc5/cvc5/releases/download/cvc5-${cvc5_version}/${cvc5_archive_name}.zip" -O /opt/cvc5.zip; \
	test "$(sha256sum /opt/cvc5.zip)" = "d18f174ff9a11923c32c3f871f844ed16bd77a28f51050b8e7c8d821c98a1c2e  /opt/cvc5.zip"; \
	unzip -j /opt/cvc5.zip "${cvc5_archive_name}/bin/cvc5" -d /usr/bin; \
	rm -f /opt/cvc5.zip;

FROM base AS libraries

# EVMONE
RUN set -ex; \
	wget -O /usr/src/evmone.tar.gz https://github.com/ipsilon/evmone/releases/download/v0.16.0/evmone-0.16.0-linux-x86_64.tar.gz; \
	test "$(sha256sum /usr/src/evmone.tar.gz)" = "09a59e07bde21bbf08b821db9097ef4db9ff06f1484b7b14497a16a701e72233  /usr/src/evmone.tar.gz"; \
	cd /usr; \
	tar -xf /usr/src/evmone.tar.gz; \
	rm -rf /usr/src/evmone.tar.gz

FROM base
COPY --from=libraries /usr/lib /usr/lib
COPY --from=libraries /usr/bin /usr/bin
COPY --from=libraries /usr/include /usr/include
COPY --from=libraries /opt/eldarica /opt/eldarica
ENV PATH="$PATH:/opt/eldarica"
